package com.test.helloworld.dao;

import com.javatest.dao.DaoBase;
import com.test.helloworld.bean.Product;

import java.util.List;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/7 11:29
 */
public class ProductDao extends DaoBase<Product> implements IProductDao {
    @Override
    public Long saveProduct(Product product) {
        String sql = "INSERT INTO product(product_name, product_desc, product_price) VALUES(?,?,?)";
        return Long.parseLong(insertReturnPk(sql, product.getProductName(), product.getProductDesc(), product.getProductPrice()).toString());
    }

    @Override
    public List<Product> getAllProduct() {
        String sql = "SELECT p.id, p.product_name as productName, p.product_desc as p.productDesc, p.product_price as productPrice FROM product as p";
        return getForList(sql);
    }
}
